package com.ruoyi.biz.index.service;

import com.google.common.collect.Maps;
import com.ruoyi.biz.index.pojo.ShortcutReq;
import com.ruoyi.biz.index.pojo.ShortcutVO;
import com.ruoyi.common.annotation.DataScope;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Component
public class HomeService implements CommandLineRunner {

    private final static Map<HomePageEnum, ShortcutVO> SHORTCUT_MAP = Maps.newLinkedHashMap();

    @PostConstruct
    private void homeService() {

        for (HomePageEnum value : HomePageEnum.values()) {
            SHORTCUT_MAP.put(value, ShortcutVO.builder().router(value.getRouter()).icon(value.getIcon()).name(value.getName()).permission(value.getPermission()).build());
        }

    }

    @Override
    public void run(String... args) throws Exception {
        this.init();
    }

    private void init() {

    }

    @DataScope(deptAlias = "t", ownerAlias = "t")
    public List<ShortcutVO> getShortcuts(ShortcutReq shortcutReq) {
        for (Map.Entry<HomePageEnum, ShortcutVO> homeMap : SHORTCUT_MAP.entrySet()) {
            switch (homeMap.getKey()) {
                case AssetApply:
                    homeMap.getValue().setBadge(1L);
                    break;
                case AssetCancel:
                    homeMap.getValue().setBadge(1000L);
                    break;
                case Change:
                    break;
                case Outer:
                    break;
                case UsedApply:
                    break;
                default:
                    break;
            }
        }
        return SHORTCUT_MAP.entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toList());
    }

    enum HomePageEnum {
        AssetApply("User", "apply", "用户管理", ""),
        AssetCancel("AssetCancel", "apply", "模块2", ""),
        Change("Change", "peoples", "模块3", ""),
        Outer("AssetApplyOuter", "user", "模块4", ""),
        InstallApply("InstallApply", "system", "模块5", ""),
        UsedApply("UsedApply", "log", "模块6", ""),
        CheckApply("CheckApply", "tool", "模块7", ""),
        CheckResult("CheckResult", "education", "模块8", ""),
        ;

        private final String icon;
        private final String router;
        private final String name;
        private final String permission;

        HomePageEnum(String router, String icon, String name, String permission) {
            this.icon = icon;
            this.router = router;
            this.name = name;
            this.permission = permission;
        }

        public String getIcon() {
            return icon;
        }

        public String getName() {
            return name;
        }

        public String getRouter() {
            return router;
        }

        public String getPermission() {
            return permission;
        }
    }

}
